#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author:liang futing
#@Time :2019/4/17 11:26
import json
from django.views.generic import ListView,UpdateView

from apps.custom import SandboxCreateView,SandboxUpdateView,BreadcrumbMixin
from .mixin import LoginRequiredMixin
from .models import Menu



class MenuCreateView(SandboxCreateView):
    model = Menu
    fields = '__all__'
    extra_context = dict(menu_all=Menu.objects.all())

    def get_context_data(self,**kwargs):
        kwargs['menu_all']=Menu.objects.all()
        return super().get_context_data(**kwargs)

class MenuListView(LoginRequiredMixin,BreadcrumbMixin,ListView):
    model = Menu
    context_object_name = 'menu_all'

class MenuUpdateView(SandboxUpdateView):
    model=Menu
    fields = '__all__'
    template_name_suffix = '_update'
    success_url = '/system/rbac/menu'
    extra_context = dict(menu_all=Menu.objects.all())

    def get_context_data(self,**kwargs):
        kwargs['menu_all']=Menu.objects.all()
        return super().get_context_data(**kwargs)